package remark;

import java.util.Scanner;

public class remarkindex {
    Remark[] remarks=new Remark[50];
    int count=0;

    public void Start(){
        System.out.println("------智能通讯录--------");
        System.out.println("1.添加记录");
        System.out.println("2.修改记录");
        System.out.println("22.查询全部");
        System.out.println("3.根据姓名查询通讯录");
        System.out.println("4.删除记录");

        System.out.println("5.退出");
        Scanner scanner=new Scanner(System.in);

        while (true){

            System.out.println("请输入（1-5）来确定操作");
            int num=scanner.nextInt();
            switch (num){
                case 1:
                    add();
                    break;
                case 2:
                    update();
                    break;
                case 3:
                    select();
                    break;
                case 4:
                    shanchu();
                    break;
                case 5:
                    logout();
                    break;
                case 22:
                    selectall();
            }
        }
    }
    private void add(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入id");
        String rid=scanner.next();
        System.out.println("请输入名字");
        String rname=scanner.next();
        System.out.println("请输入电话");
        String rphone=scanner.next();
        System.out.println("请输入性别");
        String rmax=scanner.next();


        boolean iscf=false;
        if(count!=0){
            for(int i=0;i<count;i++){
                if(remarks[i].getRname().equals(rname)){
                    iscf=true;
                }
            }

        }
        if(iscf == true){
            System.out.println("该用户已存在，请重新添加");
        }else{
            Remark remark=new Remark(rid,rname,rphone,rmax);

            remarks[count]=remark;
            count++;
            System.out.println("添加成功");
        }

    }
    private void update(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入要修改的姓名");
        String rname=scanner.next();
        for (int i=0;i<count;i++){
            if(remarks[i].getRname().equals(rname)){
                System.out.println("请输入id");
                String rid=scanner.next();
                System.out.println("请输入姓名");
                String rname1=scanner.next();
                System.out.println("请输入电话");
                String rphone=scanner.next();
                System.out.println("请输入性别");
                String rmax=scanner.next();
                Remark remark=new Remark(rid,rname1,rphone,rmax);
                remarks[i]=remark;

            }
        }

    }
    private void select(){
        Scanner scanner=new Scanner(System.in);
        System.out.println("请输入姓名");
        String rname=scanner.next();

        for (int i=0;i<count;i++){

            if (remarks[i].getRname().equals(rname)){

                System.out.println("序号:"+remarks[i].rid+"姓名:"+remarks[i].rname+"电话"+remarks[i].rphone+"性别"+remarks[i].rmax);

            }
        }
    }
   private void selectall(){
        for (int i=0;i<count;i++){
            System.out.println("序号:"+remarks[i].rid+"姓名:"+remarks[i].rname+"电话"+remarks[i].rphone+"性别"+remarks[i].rmax);

        }

   }
    private void shanchu(){
        System.out.println("请输入你要删除的人");
        Scanner scanner=new Scanner(System.in);
        String rname=scanner.next();
        Remark[] remarks1=new Remark[10];
        for(int i=0;i<count;i++){
            if(remarks[i].getRname().equals(rname)){

            }else{
                remarks1[i]=remarks[i];
            }
        }
        remarks=remarks1;
        count--;
        System.out.println("删除成功");
    }
    private void logout(){
        System.out.println("下次再见");
    }
}
